#include<bits/stdc++.h>
#define f first
#define pr pair
#define s second
#define ll long long
#define mp make_pair
#define pll pr<ll,ll>
#define pii pr<int,int>
#define piii pr<int,pii>
using namespace std;
ll d[100005],v[100005],a[100005];
ll ps[100005];
pii nd[100005];
int t;
void sl()
{
    int n,m;
    ll l,k;
    cin>>n>>m>>l>>k;
    for(int i=0;i<n;i++) cin>>d[i]>>v[i]>>a[i];
    for(int i=0;i<m;i++) cin>>ps[i];
    t=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]==0)
        {
            if(v[i]<=k) continue;
            int s=(int)(lower_bound(ps,ps+m,d[i])-ps);
            if(s<m) nd[t++]=mp(s,m-1);
        }
        else if(a[i]<0)
        {
            if(v[i]<=k) continue;
            ll g=(v[i]*v[i]-k*k-1)/(-2*a[i]);
            int s=(int)(lower_bound(ps,ps+m,d[i])-ps);
            int r=(int)(upper_bound(ps,ps+m,g+d[i])-ps);
            if(s<r) nd[t++]=mp(s,r-1);
        }
        else
        {
            int s=(int)(lower_bound(ps,ps+m,d[i])-ps);
            if(v[i]<=k)
            {
                ll g=(k*k-v[i]*v[i])/(2*a[i]);
                s=(int)(upper_bound(ps,ps+m,d[i]+g)-ps);
            }
            if(s<m) nd[t++]=mp(s,m-1);
        }
    }
    for(int i=0;i<t;i++) swap(nd[i].f,nd[i].s);
    sort(nd,nd+t);
    for(int i=0;i<t;i++) swap(nd[i].f,nd[i].s);
    int ls=-1;
    int op=0;
    for(int i=0;i<t;i++)
    {
//        cout<<"Fd "<<nd[i].f<<' '<<nd[i].s<<endl;
        if(ls<nd[i].f) ls=nd[i].s,op++;
    }
    cout<<t<<' '<<m-op<<endl;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios_base::sync_with_stdio(0);
    int tc;
    cin>>tc;
    while(tc--) sl();
    return 0;
}/*1
10 10 150307 247
62978 968 -5
51700 883 -3
40408 564 -1
60366 870 -41
35943 797 -7
47476 595 -11
59020 672 -10
81024 964 -11
80637 695 -5
66114 874 -1
46720 48066 57373 60882 68842 72773 82820 116695 122159 150307
*/
